﻿using Barcode_Project.Entity;
using Barcode_Project.InitPrint;
using Barcode_Project.Local;
using Barcode_Project.Network;
using Barcode_Project.ProBarPrint;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Alerter;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraGrid.Columns;
using log4net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NPOI.POIFS.Properties;
using NPOI.SS.Formula.Functions;
using NPOI.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ZXing;
using static System.Net.WebRequestMethods;

namespace Barcode_Project.CutPrint
{
    public partial class CutRollPrint : DevExpress.XtraEditors.XtraForm
    {

        Dictionary<string, string> datas;
        HttpAgreement http;
        ILog _log;

        decimal proMeter = 0.0m;

        public CutRollPrint(Dictionary<string, string> pars)
        {
            _log = LogManager.GetLogger(this.GetType().Name);
            InitializeComponent();
            datas = pars;
            http = new HttpAgreement();
            new ComputerTask().LoadPrinter(select_printer);
            new ComputerTask().LoadTemplate(select_template);
        }
        private void CutRollPrint_Load(object sender, EventArgs e)
        {

            try
            {
                CommonMethods.SetFormValue(this.group_data.Controls, datas, "input_");

                InitCuttingPlan();
                input_happenDate.EditValue = DateTime.Now.ToString("yyyy-MM-dd");
                LoadPrintedBarCodes();
                GetGYPrintData();
                CheckGongXu();
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

        List<CutPlanItem> cutPlanList = new List<CutPlanItem>();
        /// <summary>
        /// 根据计划编码 加载分切方案
        /// </summary>

        // 新的加载分切方案的方法
        List<CutTreeItem> treeList;

        void InitCuttingPlan()
        {
            treeList = new List<CutTreeItem>();

            var plCode = datas["plCode"];

            var uploadDic = new Dictionary<string, string>();
            uploadDic["plCode"] = plCode;
            uploadDic["gxCode"] = datas["gxCode"];

            string url = CommonMethods.APIUrl() + "FenQieList";
            var info = http.HttpPost(url, JsonConvert.SerializeObject(uploadDic));

            if (string.IsNullOrWhiteSpace(info))
            {
                XtraMessageBox.Show("接口返回信息为空", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            var obj = JsonConvert.DeserializeObject<JObject>(info);

            if (bool.Parse(obj["result"].ToString()))
            {
                treeList.Clear();

                var cutList = JsonConvert.DeserializeObject<List<SubCut>>(obj["data"].ToString());

                var index = 0;
                foreach (var father in cutList)
                {
                    treeList.Add(new CutTreeItem
                    {
                        Id = index.ToString(),
                        formulaIndex = index,
                        proName = father.proName,
                        spec = father.spec,
                        proCode = father.proCode,
                        number = father.number,
                        fqSpecs = father.fqSpecs,
                        barCode = "[请选择条码]",
                    });

                    index++;
                }

                // 先将子对象存在临时列表中，防止污染主列表数据
                var subTreeList = new List<CutTreeItem>();

                var subId = 0;
                foreach (var fa in treeList)
                {
                    var currentIndex = fa.Id;
                    var fqSpecs = fa.fqSpecs;
                    var fatherProCode = fa.proCode;
                    var subChilds = cutList.Where(c => c.fqSpecs == fqSpecs && c.proCode==fatherProCode).First().fqList;

                    // 子列表渲染
                    foreach (var sub in subChilds)
                    {
                        // 替换存货规格  xxcm*nc
                        var cmIndex = 0;
                        if(fa.spec.IndexOf("*") > -1)
                        {
                            if (fa.spec.IndexOf("cm") > -1)
                            {
                                //规格中有单位
                                cmIndex = fa.spec.IndexOf("cm");
                            }
                            else
                            {
                                cmIndex = fa.spec.IndexOf("*");
                            }
                        }
                        
                        var tail = fa.spec.Substring(cmIndex, fa.spec.Length - cmIndex);
                        var subSpec = sub.fqSpec + tail;

                        subTreeList.Add(new CutTreeItem
                        {
                            Id = "s" + subId,
                            //parentId = currentIndex,
                            formulaIndex = fa.formulaIndex,
                            fqSpecs = fa.fqSpecs,
                            spec = subSpec,
                            number = fa.number,
                            meter = sub.fqValue,
                            proCode = "[请选择存货]",
                            barCode = "[请选择条码]"
                        });
                        subId++;
                    }
                }

                treeList.Clear();

                treeList.AddRange(subTreeList);

                treeList_cuttingPlan.KeyFieldName = "Id";
                treeList_cuttingPlan.ParentFieldName = "parentId";

                treeList_cuttingPlan.DataSource = treeList;

                treeList_cuttingPlan.OptionsBehavior.Editable = false;

                treeList_cuttingPlan.ExpandAll();

                treeList_cuttingPlan.Columns[0].Width = 10;
            }
        }

        string gyPrintData = "";
        /// <summary>
        /// 获取工艺参数配置
        /// </summary>
        private void GetGYPrintData()
        {
            var queryDic = new Dictionary<string, string>();
            queryDic["plCode"] = datas["plCode"];
            queryDic["gxCode"] = datas["gxCode"];
            string url = CommonMethods.APIUrl() + "GetPrintGYData";
            var info = http.HttpPost(url, JsonConvert.SerializeObject(queryDic));
            if (string.IsNullOrWhiteSpace(info))
            {
                XtraMessageBox.Show("接口返回信息为空", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            var obj = JsonConvert.DeserializeObject<JObject>(info);

            if (bool.Parse(obj["result"].ToString()))
            {
                gyPrintData = obj["data"].ToString();
            }
        }

        JObject cgx = new JObject();
        private void CheckGongXu()
        {
            var queryDic = new Dictionary<string, string>();
            queryDic["plCode"] = datas["plCode"];
            queryDic["gxCode"] = datas["gxCode"];
            string url = CommonMethods.APIUrl() + "CheckPlanGongXu";
            var info = http.HttpPost(url, JsonConvert.SerializeObject(queryDic));
            if (string.IsNullOrWhiteSpace(info))
            {
                XtraMessageBox.Show("接口返回信息为空", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            var obj = JsonConvert.DeserializeObject<JObject>(info);

            if (bool.Parse(obj["result"].ToString()))
            {
                cgx =JsonConvert.DeserializeObject<JObject>(obj["data"].ToString());
            }
        }
        /// <summary>
        /// 打印提交对象
        /// </summary>
        Dictionary<string, object> uploadData = new Dictionary<string, object>();

        // 关联条码
        List<NeedCutBarCode> outputBarCodes { get; set; }

        Dictionary<int, List<NeedCutBarCode>> relativeBarCodes_Dic = new Dictionary<int, List<NeedCutBarCode>>();
        private void button_print_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                //验证必填项
                if (!CheckBeforePrint())
                {
                    return;
                }

                // 验证分切列表数据
                var verifyResult = VerifyCutRowData();

                if (!verifyResult)
                {
                    return;
                }
                var uploadDic = CollectListData();

                if (uploadDic == null)
                {
                    return;
                }

                string url = CommonMethods.APIUrl() + "SaveBarCode";
                var info = http.HttpPost(url, JsonConvert.SerializeObject(uploadDic));

              
                if (string.IsNullOrWhiteSpace(info))
                {
                    XtraMessageBox.Show("接口返回信息为空", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                var obj = JsonConvert.DeserializeObject<JObject>(info);
                if (bool.Parse(obj["result"].ToString()))
                {

                    var cutData = new Dictionary<string, string>(datas);

                    var oldTable = CommonMethods.CreatePrintTableByDictionary(cutData, obj["data"].ToString());

                    var printerName = ((ItemSelector)select_printer.GetSelectedDataRow()).code;
                    var templatePath = ((ItemSelector)select_template.GetSelectedDataRow()).code;//模板路径

                    var table = new DataTable();
                    table.Columns.Add("proCode");
                    table.Columns.Add("proName");
                    table.Columns.Add("number");
                    table.Columns.Add("relationBar");
                    table.Columns.Add("spec");
                    table.Columns.Add("proMeter");
                    table.Columns.Add("weight");
                    table.Columns.Add("barCode");
                    table.Columns.Add("cu_batch");
                    table.Columns.Add("happenDate");
                    table.Columns.Add("cu_material");
                    table.Columns.Add("cu_qualityLevel");
                    table.Columns.Add("cu_shelfLife");
                    table.Columns.Add("cu_shelfLifeUnit");
                    table.Columns.Add("pusersName");
                    table.Columns.Add("pusers");
                    table.Columns.Add("unitName");
                    table.Columns.Add("zhxBz");
                    var selectRowIndex = treeList_cuttingPlan.Selection.First().Id;
                    var selectedCut = treeList[selectRowIndex];

                    CutTreeItem parentCut;
                    List<CutTreeItem> cutChilds;

                    cutChilds = treeList.Where(t => t.formulaIndex == selectedCut.formulaIndex).ToList();

                    var barArr = obj["data"].ToString().Split(',');

                    JObject gyDataJson= new JObject();
                    if (!string.IsNullOrWhiteSpace(gyPrintData))
                    {
                        gyDataJson = JsonConvert.DeserializeObject<JObject>(gyPrintData);
                    }
                    foreach (var gx_obj in gyDataJson)
                    {
                        if (!table.Columns.Contains(gx_obj.Key.ToString()))
                        {
                            table.Columns.Add(gx_obj.Key.ToString());
                        }
                    }


                    int i = 0;
                    foreach (var child in cutChilds)
                    {
                        for (int j = 0; j < int.Parse(child.number); j++)
                        {
                            var row = table.NewRow();
                            row["proCode"] = child.proCode;
                            row["proName"] = child.proName;
                            row["number"] = child.weight;
                            row["relationBar"] = child.barCode;

                            var dt = getRelationBarInfo(child.barCode);
                            if (dt.Rows.Count > 0)
                            {
                                row["cu_qualityLevel"] = dt.Rows[0]["cu_qualityLevel"].ToString();
                                row["cu_shelfLife"] = dt.Rows[0]["cu_shelfLife"].ToString();
                                row["cu_shelfLifeUnit"] = dt.Rows[0]["cu_shelfLifeUnit"].ToString();
                                row["unitName"] = child.proUnit;
                                if (row["unitName"].ToString() == "千克")
                                {
                                    row["number"] = child.weight;
                                }
                                else
                                {
                                    row["number"] = child.meter;
                                }
                            }
                            if (cgx.Property("isLast") != null && cgx["isLast"].ToString() == "1")
                            {
                                row["zhxBz"] = cgx["biaozhun"].ToString();
                                row["cu_material"] = cgx["caizhi"].ToString();
                            }
                            else
                            {
                                row["cu_material"] = dt.Rows[0]["cu_material"].ToString();
                                row["zhxBz"] = child.zhxBz;
                            }
                            row["spec"] =child.spec;
                            row["proMeter"] = child.meter;
                            row["barCode"] = barArr[i];
                            row["cu_batch"] = input_cu_batch.Text;
                            row["happenDate"] = input_happenDate.Text;
                            row["pusersName"] = input_pusers.Text;
                            row["pusers"] = input_pusers.Text;

                            foreach (var gx_obj in gyDataJson)
                            {
                                if (gx_obj.Value!=null && !string.IsNullOrWhiteSpace(gx_obj.Value.ToString()))
                                {
                                    row[gx_obj.Key.ToString()]=gx_obj.Value.ToString();
                                }
                            }
                            table.Rows.Add(row);

                            i++;
                        }

                    }
                    
                    new ComputerTask().StartPrintingTask(table, printerName, templatePath);
       

                    LoadPrintedBarCodes();
                }
                else
                {
                    XtraMessageBox.Show(obj["message"].ToString(), "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }


        // 获取关联条码信息
        DataTable getRelationBarInfo(string barCode)
        {
            var table = new DataTable();

            try
            {
                var queryDic = new Dictionary<string, string>();
                queryDic["barCode"] = barCode;

                string url = CommonMethods.APIUrl() + "getRelationBarInfo";
                var info = http.HttpPost(url, JsonConvert.SerializeObject(queryDic));

                if (string.IsNullOrWhiteSpace(info))
                {
                    XtraMessageBox.Show("接口返回信息为空", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                var obj = JsonConvert.DeserializeObject<JObject>(info);

                if (bool.Parse(obj["result"].ToString()))
                {
                    table = JsonConvert.DeserializeObject<DataTable>(obj["data"].ToString());
                }
                else
                {
                    XtraMessageBox.Show(obj["message"].ToString(), "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return table;
        }


        // 打印之前，检查必填项
        private bool CheckBeforePrint()
        {
            var result = false;
            if (input_cu_batch.EditValue == null || string.IsNullOrEmpty(input_cu_batch.EditValue.ToString()))
            {
                XtraMessageBox.Show("请填写批号");
                return result;
            }
            if (string.IsNullOrEmpty(input_pusers.Text.ToString()))
            {
                XtraMessageBox.Show("请填写生产人员");
                return result;
            }
            if (input_happenDate.EditValue == null || string.IsNullOrEmpty(input_happenDate.EditValue.ToString()))
            {
                XtraMessageBox.Show("请选择开始日期");
                return result;
            }
            result = true;
            return result;
        }



        //验证分切列表

        bool VerifyCutRowData()
        {
            var selectRowIndex = treeList_cuttingPlan.Selection.First().Id;
            var selectedCut = treeList[selectRowIndex];

            var childs = treeList.Where(t => t.formulaIndex == selectedCut.formulaIndex);

            foreach (var cut in childs)
            {
                if (cut.barCode.Contains("["))
                {
                    XtraMessageBox.Show("请选择分切条码");
                    return false;
                }

                if (cut.proCode.Contains("["))
                {
                    XtraMessageBox.Show("请选择存货");
                    return false;
                }
                if (select_printer.GetSelectedDataRow() == null)
                {
                    XtraMessageBox.Show("请选择打印机");
                    return false;
                }
                if (select_template.GetSelectedDataRow() == null)
                {
                    XtraMessageBox.Show("请选择打印模板");
                    return false;
                }

                if (string.IsNullOrEmpty(cut.weight))
                {
                    XtraMessageBox.Show("请录入重量");
                    return false;
                } 
                
            }


            return true;
        }
        Dictionary<string, object> CollectListData()
        {
            bool relativeCheck = GenerateRelativeBarCodesDictionary();

            if (!relativeCheck)
            {
                return null;
            }

            var selectRowIndex = treeList_cuttingPlan.Selection.First().Id;
            var selectedCut = treeList[selectRowIndex];

            List<CutTreeItem> cutChilds;

            // 原来的relativeBar已经被占用了
            uploadData["relativeBarCodes"] = selectedCut.barCode;
            uploadData["userCode"] = datas["userCode"];
            uploadData["plCode"] = input_plCode.EditValue.ToString();
            uploadData["barType"] = "SC";
            uploadData["gxCode"] = datas["gxCode"].ToString();
            uploadData["happenDate"] = input_happenDate.EditValue.ToString().Replace('/', '-');
            uploadData["cu_batch"] = input_cu_batch.EditValue.ToString();

            uploadData["pusers"] = input_pusers.Text;

            uploadData["baseCode"] = datas["baseCode"];
            uploadData["userCode"] = datas["userCode"]; 

            var listDic = new List<Dictionary<string, string>>();

            foreach (var cutItem in treeList.Where(t => t.formulaIndex == selectedCut.formulaIndex))
            {
                for (int i = 0; i < int.Parse(cutItem.number); i++)
                {
                    var cutDic = new Dictionary<string, string>();
                    cutDic["proCode"] = cutItem.proCode;
                    cutDic["proName"] = cutItem.proName;
                    cutDic["meter"] = cutItem.meter;
                    cutDic["weight"] = cutItem.weight;

                    listDic.Add(cutDic);
                }
            }

            uploadData["list"] = listDic;

            return uploadData;
        }
        bool GenerateRelativeBarCodesDictionary()
        {
            var selectRowIndex = treeList_cuttingPlan.Selection.First().Id;
            var selectedCut = treeList[selectRowIndex];

            var dicItem = new List<NeedCutBarCode>();

            if (relativeBarCodes_Dic.ContainsKey(selectedCut.formulaIndex))
            {
                dicItem = relativeBarCodes_Dic[selectedCut.formulaIndex];
            }

            // 如果没有选过关联条码
            if (dicItem == null || dicItem.Count == 0)
            {
                return true;
            }

            var listDic = new List<Dictionary<string, string>>();

            foreach (var bar in dicItem)
            {
                var meterTestNum = 0.0m;
                decimal.TryParse(bar.usedMeter, out meterTestNum);

                var weightTestNum = 0.0m;
                decimal.TryParse(bar.usedWeight, out weightTestNum);


                if (meterTestNum == 0.0m || weightTestNum == 0.0m)
                {
                    XtraMessageBox.Show("关联条码重量或米数错误，请检查输入内容是否正确");
                    return false;
                }

                var dic = new Dictionary<string, string>();
                dic["barCode"] = bar.barCode;
                dic["proWeight"] = bar.proWeight;
                dic["proMeter"] = bar.proMeter;
                dic["useWeight"] = bar.usedWeight;
                dic["useMeter"] = bar.usedMeter;
                dic["proCode"] = bar.proCode;

                listDic.Add(dic);
            }

            uploadData["relationBar"] = JsonConvert.SerializeObject(listDic);
            var cu_iUnitCost = 0.0m;
            var cu_batch = "";

            datas["cu_iUnitCost"] = cu_iUnitCost.ToString();
            datas["cu_batch"] = cu_batch;

            return true;
        }

        private void button_exit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var result = XtraMessageBox.Show("确定要退出程序吗？", "请确认", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                Application.Exit();
            }
        }

        // 分切存货选择按钮
        private void button_clear_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
         
        }

        private void button_refreshCuttingPlan_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //LoadCuttingPlan();
            InitCuttingPlan();
        }

        private void button_update_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var r = XtraMessageBox.Show("即将关闭程序进行升级，是否继续？", "提示", MessageBoxButtons.OKCancel);
            if (r == DialogResult.OK)
            {
                new RemoteRequest().UpdateCmdProgram();
            }
        }

        private void planList_cuttingPlan_RowCellClick(object sender, DevExpress.XtraTreeList.RowCellClickEventArgs e)
        {
            selectionFlag = false;

            var node = e.Node;

            var cutItem = treeList[node.Id];

            if (relativeBarCodes_Dic.ContainsKey(cutItem.formulaIndex))
            {
                gridControl_relativeBarCodes.DataSource = relativeBarCodes_Dic[cutItem.formulaIndex];
            }


            if (e.Column.FieldName == "barCode")
            {
                // 获取计划编码 
                var plCode = datas["plCode"];
                //var gxCode = "FQ";
                var gxCode = datas["gxCode"];

                // 弹出条码选择界面
                var win = new CutBarCodeSelector(plCode, gxCode, cutItem.spec);
                win.ShowDialog();

                if (win.DialogResult == DialogResult.OK)
                {
                    outputBarCodes = win.outputBarCodes;
                    relativeBarCodes_Dic[cutItem.formulaIndex] = win.outputBarCodes;

                    gridControl_relativeBarCodes.DataSource = win.outputBarCodes;

                    var barCodesArr = outputBarCodes.Select(o => o.barCode).ToArray();

                    treeList[node.Id].barCode = string.Join(",", barCodesArr);
                    foreach (var child in treeList.Where(t => t.formulaIndex == cutItem.formulaIndex))
                    {
                        child.barCode = string.Join(",", barCodesArr);
                    }

                    treeList_cuttingPlan.RefreshDataSource();


                }
            }

            if (e.Column.FieldName == "proCode" || e.Column.FieldName == "proName")
            {
                var win = new ProductSelector(cutItem.spec);
                win.ShowDialog();

                if (win.DialogResult == DialogResult.OK)
                {
                    // 检查是否由相同规格，提示自动赋值
                    var sameList = treeList.Where(t => t.formulaIndex == cutItem.formulaIndex && t.spec == cutItem.spec).ToList();

                    if (sameList.Count > 1)
                    {
                        var result = XtraMessageBox.Show("当前分切方案检测到相同规格，是否自动添加当前存货信息？", "提示", MessageBoxButtons.YesNo);
                        if (result == DialogResult.Yes)
                        {
                            foreach (var sameObj in sameList)
                            {
                                sameObj.proCode = win.selectedPro["proCode"];
                                sameObj.proName = win.selectedPro["proName"];
                                sameObj.proUnit = win.selectedPro["proUnit"];
                                sameObj.spec = win.selectedPro["spec"];
                            }
                        }
                        else
                        {
                            treeList[node.Id].proCode = win.selectedPro["proCode"];
                            treeList[node.Id].proName = win.selectedPro["proName"];
                            treeList[node.Id].proUnit = win.selectedPro["proUnit"];
                            treeList[node.Id].spec = win.selectedPro["spec"];
                        }
                    }
                    else
                    {
                        treeList[node.Id].proCode = win.selectedPro["proCode"];
                        treeList[node.Id].proName = win.selectedPro["proName"];
                        treeList[node.Id].proUnit = win.selectedPro["proUnit"];
                        treeList[node.Id].spec = win.selectedPro["spec"];
                    }

                    treeList_cuttingPlan.RefreshDataSource();
                }
            }

            // 如果是米数，弹出输入框
            if (e.Column.FieldName == "meter")
            {
                var win = new CutMeterInputDialog();
                win.ShowDialog();

                if (win.DialogResult == DialogResult.OK)
                {
                    treeList[node.Id].meter = win.confirmNum;
                    treeList_cuttingPlan.RefreshDataSource();
                }
            }

            // 如果是重量，弹出输入框
            if (e.Column.FieldName == "weight")
            {
                var win = new CutMeterInputDialog();
                win.ShowDialog();

                if (win.DialogResult == DialogResult.OK)
                {
                    treeList[node.Id].weight = win.confirmNum;
                    treeList_cuttingPlan.RefreshDataSource();
                }
            }

            // 如果是轴数
            if (e.Column.FieldName == "number")
            {
                var win = new CutMeterInputDialog();
                win.ShowDialog();

                if (win.DialogResult == DialogResult.OK)
                {
                    treeList[node.Id].number = win.confirmNum;
                    treeList_cuttingPlan.RefreshDataSource();
                }
            }

            selectionFlag = true;
        }

        bool selectionFlag = false;
        string bcpSpec = "";
        private void CutRollPrint_Shown(object sender, EventArgs e)
        {
            selectionFlag = true;
        }

   
        /// <summary>
        /// 加载该计划工序下的所有已打印的条码
        /// </summary>
        void LoadPrintedBarCodes()
        {

            var list = new RemoteRequest()
                .GetPrintedBarCodes_ByPlCode_GxCode(datas["plCode"], datas["gxCode"]);

            gridControl_printedBarcodes.DataSource = list;
            gridControl_printedBarcodes.RefreshDataSource();
        }

        private void Form_SizeChanged(object sender, EventArgs e)
        {
        //    AutoSizeFormClass asc = new AutoSizeFormClass();
        //    asc.controlAutoSize(this);
        }


    }

}